import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.NavigableMap;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

public class testClass {
	//#######################################################################################
	abstract class testAbstractClass extends DoCompare1{ void doit(){}; }
	//#######################################################################################
	
	public <T> void doDosomething(List<T> list, T val){}
	
	public static void main(String args[]){
		String str = "orwa";
		System.out.println("###################### ("+str.subSequence(3, 4)+") ################################");
		bckCharSeq bckchar = new bckCharSeq();
		char[] testbck = bckchar.backwardSeq(str);
		System.out.println("###################### " + String.valueOf(testbck) + " ################################");
		
		StringBuilder strbldr = new StringBuilder("orwa");
		
		System.out.println("Length=" + strbldr.length() ); 
		System.out.println("capacity=" + strbldr.capacity() );
		
		strbldr.append("Badran");
		
		System.out.println("Length=" + strbldr.length() ); 
		System.out.println("capacity=" + strbldr.capacity() );
		
		System.out.println(strbldr);
		
		strbldr = new StringBuilder("orwa");
		
		strbldr.insert(4, "Mohed");
		
		System.out.println(strbldr);
		
		System.out.println("delete op: " + strbldr.delete(4, 9));
		
		int [] [] array = {{0}, {0, 1}, {0, 2, 4}, {0, 3, 6, 9}, {0, 4, 8, 12, 16}};
		
		System.out.println(array [4] [1]);
	//	System.out.println (array [1][4]);
		
		System.out.println("result: "+1+3*2);
		
		//new String("Hello World").charAt(11);
		
		int[] xx = null;
		System.out.println(xx);
		
		Object objarray[];
		
		int yy = 1;
		
		strbldr.append(" Hello ").append("My Name ").append("Is ").append("Slim Shady!!");
		System.out.println(strbldr);
		
		strbldr.append("string" + 5);
		System.out.println(strbldr);
		
		StringBuilder strbldr2 = new StringBuilder();
		strbldr2.append("strbldr2");
		System.out.println(strbldr2);
		
		strbldr2.insert(0, "helloo" + yy);
		
		ArrayList al1 = new ArrayList();
		ArrayList al2 = new ArrayList();
		for (int i = 0; i <= 5; i++) {
			al1.add(i);
			al2.add(i+5);
		}
		
		System.out.println(al1);
		System.out.println(al2);
		
		al1.set(2, "Ali");
		al2.add(3, "sally");
				
		System.out.println("****************************");
		System.out.println(al1);
		System.out.println(al2);
		
		System.out.println(al1.indexOf("Ali"));
		System.out.println(al1.retainAll(al2));
		System.out.println(al1);
		System.out.println(al2.contains(5));
		System.out.println(al2.subList(2, 5));
		
		al2.size();
		
		String[] table = {"a", "b", "c"};
		int ii = 0;
		do
			while(ii < table.length)
				System.out.println(ii++);
		while(ii < table.length);
		
		List l1 = new ArrayList();
		Iterator it = al2.iterator();
		System.out.println("********" + it.next());
		System.out.println("********" + it.next());

//##################################################################################################################
//############################ Using Singleton #####################################################################
//##################################################################################################################		
		BillPughSingleton singObj = null;
		System.out.println(singObj);
		
		singObj = BillPughSingleton.LazyHolder.getSingInstance();
		
		if ( singObj != null ) {
			System.out.println("singObj intialized and id is: "+ singObj);
		}
		
		BillPughSingleton singObj2 = null;
		System.out.println(singObj2);
		
		singObj2 = BillPughSingleton.LazyHolder.getSingInstance();

		if ( singObj2 != null ) {
			System.out.println("singObj intialized and id is: "+ singObj2);
		}
//##################################################################################################################		
		
		List<Integer> listIter = new ArrayList<Integer>();
		listIter.add(10);
		listIter.add(20);
		listIter.set(0, 100);
		System.out.println(listIter);
		
//##################################################################################################################
	//using generics
		List <Number> listNum1 = new ArrayList<Number>();
		//compile error *** type mismatch, to solve this must use wildcards
		//List <Number> listNum1 = new ArrayList<Integer>();
	
	//using wildcards		
		List<?> numList = new ArrayList<String>();
		//compile error **** cannot change a wildcard object, it won't be type safe!!
		//numList.add(new String("Cannot use a method that changes to wildcard object"));
		
		numList = new ArrayList<Integer>();
		System.out.println(numList);
		
	//using bounded wildcard, to restrict wildcard to certain Class type and its derived classes
		List<? extends Number> numList3 = new ArrayList<Integer>();
		List<? extends Number> numList4 = new ArrayList<Float>();
		List<? extends Number> numList5 = new ArrayList<Double>();
		List<? super Double> numList6 = new ArrayList<Number>();
				
		//compile error *** numList3 bounded to Number and its derived classes
		//numList3 = new ArrayList<String>();
		
		Set<Character> organSet = new TreeSet<Character>(); 
		String treeStr = "the quick brown fox jumps over the lazy doggg";
		for(char strIter : treeStr.toCharArray()){
			organSet.add(strIter);
		}
		
		System.out.println(organSet);
		
		NavigableMap<Integer, String> examScores = new TreeMap<Integer, String>();
		examScores.put(90, "Sophia");
		examScores.put(20, "Isabella");
		examScores.put(10, "Emma");
		examScores.put(50, "Olivea");
		examScores.put(50, "Smarty");
		
		System.out.println(examScores);
		System.out.println(examScores.containsKey(100) );
		System.out.println("ceilingEntry: " + examScores.ceilingEntry(45) );
		
		String testCompare = "aaaa";
		String testCompare1 = "bbbb";
		String testCompare2 = "aaaa";
		System.out.println(testCompare.compareTo(testCompare1));
		System.out.println(testCompare.compareTo(testCompare2));
		System.out.println(testCompare1.compareTo(testCompare));
		
		Integer intComp = new Integer(1);
		Integer intComp1 = new Integer(5);
		System.out.println("int comparison");
		System.out.println(intComp.compareTo(intComp1));
		System.out.println(intComp1.compareTo(intComp));
		System.out.println(intComp1.compareTo(new Integer(5)));
		
		List<Integer> testColl = new ArrayList<Integer>();
		testColl.add(1);
		testColl.add(4);
		testColl.add(6);
		testColl.add(5);
		testColl.add(9);
		System.out.println(testColl);
		Collections.shuffle(testColl);
		System.out.println("shuffled testColl: " + testColl);
		Collections.sort(testColl);
		System.out.println("naturally sorted testColl: " + testColl);
		Collections.rotate(testColl, 1);
		System.out.println("rotated testColl: " + testColl);
		Collections.sort(testColl);
		Collections.rotate(testColl, 3);
		System.out.println("rotated testColl: " + testColl);
		
	}

}
